<#-- Save component name -->
<#include "../auxftl/constants.ftl">
<#include "../auxftl/propertyutils.ftl">
<#-- Package and imports -->
package ${modelPackage};

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Session;

import java.util.List;

/**
 * ${entityName}DAO - ${entityName} hibernate DAO class
 * @link http://code.google.com/p/stripes-crud/ 
 */
public class ${entityName}DAO extends HibernateDAO<${entityName}, ${pojo.identifierProperty.type.returnedClass.name}> {

  /**
   * Constructor for ${entityName} DAO object
   */
  public ${entityName}DAO() {
    super();
  }

  /**
   * Constructor for ${entityName} DAO object
   * @param sessionShared true if session is shared (current session will be used)
   */
  public ${entityName}DAO(boolean sessionShared) {
    super(sessionShared);
  }

<#-- Generate search methods -->
<#foreach property in pojo.allPropertiesIterator>
<#if !c2h.isCollection(property) && property.name != pojo.identifierProperty.name && !isToOne(property) && !property.type.name?lower_case?starts_with("binary")>
<#if pojo.isComponent(property)>
<#foreach nestedProp in property.value.propertyIterator>
<#assign upperPropName = nestedProp.name?cap_first>
<#if isString(nestedProp)>

  /**
   * Finds entity instances by given criterium
   * @param ${nestedProp.name} value
   * @param ignoreCase if true case will be ignored
   * @return list of entity instances
   */
  public List findBy${upperPropName}(${nestedProp.type.returnedClass.name} ${nestedProp.name}, boolean ignoreCase) {
    Session session = giveSession();
    Criteria crit = session.createCriteria(getPersistentClass());
    if (ignoreCase) {
      crit.add(Restrictions.eq("${property.name}.${nestedProp.name}", ${nestedProp.name}).ignoreCase());
    } else {
      crit.add(Restrictions.eq("${property.name}.${nestedProp.name}", ${nestedProp.name}));
    }
    List result = crit.list();
    returnSession(session);
    return result;
  }
<#else>

  /**
   * Finds entity instances by given criterium
   * @param ${nestedProp.name} value
   * @return list of entity instances
   */
  public List findBy${upperPropName}(${nestedProp.type.returnedClass.name} ${nestedProp.name}) {
    Session session = giveSession();
    Criteria crit = session.createCriteria(getPersistentClass());
    crit.add(Restrictions.eq("${property.name}.${nestedProp.name}", ${nestedProp.name}));
    List result = crit.list();
    returnSession(session);
    return result;
  }
</#if>
</#foreach>
<#else>
<#assign upperPropName = property.name?cap_first>
<#if isString(property)>

  /**
   * Finds entity instances by given criterium
   * @param ${property.name} value
   * @param ignoreCase if true case will be ignored
   * @return list of entity instances
   */
  public List findBy${upperPropName}(${property.type.returnedClass.name} ${property.name}, boolean ignoreCase) {
    Session session = giveSession();
    Criteria crit = session.createCriteria(getPersistentClass());
    if (ignoreCase) {
      crit.add(Restrictions.eq("${property.name}", ${property.name}).ignoreCase());
    } else {
      crit.add(Restrictions.eq("${property.name}", ${property.name}));
    }
    List result = crit.list();
    returnSession(session);
    return result;
  }
<#else>

  /**
   * Finds entity instances by given criterium
   * @param ${property.name} value
   * @return list of entity instances
   */
  public List findBy${upperPropName}(${property.type.returnedClass.name} ${property.name}) {
    Session session = giveSession();
    Criteria crit = session.createCriteria(getPersistentClass());
    crit.add(Restrictions.eq("${property.name}", ${property.name}));
    List result = crit.list();
    returnSession(session);
    return result;
  }
</#if>
</#if>
</#if>
</#foreach>
}
